package gin_http

import "github.com/gin-gonic/gin"

// AuthOption 身份验证相关选项
type AuthOption struct {
	AuthHandler    gin.HandlerFunc      //指定authHandler
	AuthPacketFunc ToAuthDataPacketFunc //指定解析dataPacket的func
}

func (s *AuthOption) OptAuthHandler(defaults ...gin.HandlerFunc) gin.HandlerFunc {
	if s.AuthHandler != nil {
		return s.AuthHandler
	}

	if s.AuthPacketFunc != nil {
		return AuthByDataPacketFuncHandler(s.AuthPacketFunc)
	}
	if len(defaults) > 0 {
		return defaults[0]
	}

	return EmptyHandlerFunc
}

// AccreditOption 授权验证选项
type AccreditOption struct {
	AccreditHandler gin.HandlerFunc //指定权限校验Handler
}

func (s *AccreditOption) OptAccreditHandler(defaults ...gin.HandlerFunc) gin.HandlerFunc {
	if s.AccreditHandler != nil {
		return s.AccreditHandler
	}

	if len(defaults) > 0 {
		return defaults[0]
	}

	return EmptyHandlerFunc
}

// AuthExtendInfoOption 认证扩展信息选项
type AuthExtendInfoOption struct {
	ExtendInfoFunc func(int64) map[string]string //指定获取额外信息的方法
}
